package cn.yll.api.util;

import cn.yll.common.constant.MyConstants;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import java.util.Objects;

/**
 * @author yangll
 */
public class JwtUserUtil {
    /**
     * 获取当前登录人用户ID
     * 未登录时返回null
     */
    public static Long getLoginUserId() {
        Object id = RequestContextHolder.currentRequestAttributes().getAttribute(MyConstants.LOGIN_USER_ID, RequestAttributes.SCOPE_REQUEST);
        if (Objects.nonNull(id) && id instanceof Long) {
            return (Long) id;
        }
        return null;
    }
}
